import { formatDate } from '@src/assets/js/tool'
import { InputBatchSchema } from '@components/schema/inputBatch'
import { Space, Divider } from 'antd'
import { ColumnsType } from 'antd/es/table'
import { History } from 'history'
import { Dispatch } from 'redux'
import { addWindow } from '@redux/actions/tab';

export function getColumn (dispatch: Dispatch, hide: () => void): ColumnsType<InputBatchSchema> {
  const columns: ColumnsType<InputBatchSchema> = [
    {
      title: '序号',
      dataIndex: 'orderno',
      key: 'orderno',
      width: 75
    },
    {
      title: '导入名称',
      dataIndex: 'filename',
      key: 'filename'
    },
    {
      title: '导入时间',
      dataIndex: 'create_datetime',
      key: 'create_datetime',
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YYYY-MM-DD')
        }
      }
    },
    {
      title: '案件数',
      dataIndex: 'import_count',
      key: 'import_count'
    },
    {
      title: '失败数',
      dataIndex: 'fail_count',
      key: 'fail_count',
      render: (v: number) => {
        return <span style={{ color: 'red' }}>{v}</span>
      }
    },
    {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      width: 135,
      render: (v: string, l: InputBatchSchema) => {
        return (
          <Space split={<Divider type="vertical" />}>
            <a onClick={() => {
              hide()
              dispatch(addWindow({ id: `case--input-batch-case-list-${l.id}`, title: '批量导入案件', componentName: 'CaseInputBatchCaseList', forceRefresh: false, meta: { id: l.id } }))
            }}>查看</a>
          </Space>
        )
      }
    }
  ]
  return columns
}
